package io.kiki.stack.netty.channelManager;

import io.kiki.stack.netty.config.Config;
import io.netty.channel.ChannelHandlerContext;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Setter
@Getter
public class RpcChannelEventHandler extends ChannelEventHandler {

    public RpcChannelEventHandler() {
        super();
    }

    public RpcChannelEventHandler(Config config) {
        super(config);
    }

    @Override
    public void channelInactive(ChannelHandlerContext channelHandlerContext) throws Exception {
        Channel channel = channelHandlerContext.channel().attr(Channel.CHANNEL).get();
        if (channel != null) {
            this.getChannelManager().remove(channel);
        }
        super.channelInactive(channelHandlerContext);
    }
}
